﻿using System.Linq;
using Microsoft.SharePoint;
using WoltersKluwer.SPChainGang.Core.TimerJobs;

namespace WoltersKluwer.SPChainGang.Core.FeatureReceivers
{
    public class ChainGangFeatureReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            using (var site = properties.Feature.Parent as SPSite)
            {
                if (site == null) return;

                var jobs = from job in site.WebApplication.JobDefinitions
                           where job is ChainGangJob
                           select job;

                foreach (var job in jobs)
                    job.Delete();
            }
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
        }
    }
}
